<?php

include(dirname(__FILE__).'/../../bootstrap/functional.php');

// create a new test browser
$browser = new sfTestBrowser();

/*
 * Check if the basic code sets are listed on the page.  These are
 * fixtures and should be inserted when the plugin is built.
 */
$browser->
  get('/codesetAdmin/index')->
  isStatusCode(200)->
  isRequestParameter('module', 'codesetAdmin')->
  isRequestParameter('action', 'index')->
  checkResponseElement('body', '/Code_AUTH/')->
  checkResponseElement('body', '/Code_CLS/')->
  checkResponseElement('body', '/Code_STS/');

 /*
  * Click on the Create link and create a new code set TEST_SET
  */
$browser->
  get('/codesetAdmin/create')->
  isStatusCode(200)->
  isRequestParameter('module', 'codesetAdmin')->
  isRequestParameter('action', 'create')->
  checkResponseElement('body', '/New/')->
  setField("cm_code_set[code_set_nm]","TEST_SET")->
  setField("cm_code_set[status_cd]","I")->
  setField("cm_code_set[class_cd]","GEN")->
  setField("cm_code_set[effective_from_time][year]","2003")-> 
  setField("cm_code_set[effective_from_time][month]","1")->
  setField("cm_code_set[effective_from_time][day]","1")->
  setField("cm_code_set[effective_to_time][year]","2010")-> 
  setField("cm_code_set[effective_to_time][month]","12")->
  setField("cm_code_set[effective_to_time][day]","31")->
  click('Save')->
  isRedirected()->   // Check that request is redirected
  followRedirect()->
  checkResponseElement('body', '/TEST_SET/');
  
/*
 * Edit fields and save.
 */
$browser->
  get('/codesetAdmin/edit/code_set_nm/TEST_SET')->
  isStatusCode(200)->
  isRequestParameter('module', 'codesetAdmin')->
  isRequestParameter('action', 'edit')->
  checkResponseElement('body', '/Edit TEST_SET/')->
  setField("cm_code_set[status_cd]","A")->
  setField("cm_code_set[effective_from_time][year]","2004")-> 
  setField("cm_code_set[effective_from_time][month]","2")->
  setField("cm_code_set[effective_from_time][day]","3")->
  setField("cm_code_set[effective_to_time][year]","2009")-> 
  setField("cm_code_set[effective_to_time][month]","11")->
  setField("cm_code_set[effective_to_time][day]","30")->
  click('Save')->
  isRedirected()->   // Check that request is redirected
  followRedirect()->
  checkResponseElement('body', '/Edit TEST_SET/');

 /*
  * Click on the Create link and try to create a duplicate to TEST_SET
  */
$browser->
  get('/codesetAdmin/create')->
  isStatusCode(200)->
  isRequestParameter('module', 'codesetAdmin')->
  isRequestParameter('action', 'create')->
  checkResponseElement('body', '/New/')->
  setField("cm_code_set[code_set_nm]","TEST_SET")->
  setField("cm_code_set[status_cd]","I")->
  setField("cm_code_set[class_cd]","GEN")->
  setField("cm_code_set[effective_from_time][year]","2003")-> 
  setField("cm_code_set[effective_from_time][month]","1")->
  setField("cm_code_set[effective_from_time][day]","1")->
  setField("cm_code_set[effective_to_time][year]","2010")-> 
  setField("cm_code_set[effective_to_time][month]","12")->
  setField("cm_code_set[effective_to_time][day]","31")->
  click('Save')->
  checkResponseElement('body', '/This Code Set Name already exists./');  
  
/*
 * Delete Code Set and follow redirect to index page
 */
$browser->
  get('/codesetAdmin/delete/code_set_nm/TEST_SET')->
  isRedirected()->
  followRedirect()->
  isRequestParameter('module', 'codesetAdmin')->
  isRequestParameter('action', 'index');
  
  
  
  